﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Employees_EmpRecord : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                InitializeComponent();
                if (Request["rid"] != null)
                {
                    WMaster.SetWhere("EmpRecordID=" + Request["rid"].ToString());
                }

                if (Request["eid"] != null)
                {
                    hidEid.Value = Request["eid"].ToString();
                    hidEname.Value = Server.UrlDecode(Request["ename"].ToString());
                    spHistory.Visible = true;
                }
                else
                {
                    spHistory.Visible = false;
                }

                Master.DataSource = WMaster;




           
                MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
                master.HelpHref = "";
                master.PageName = "员工奖惩明细";
                master.PicUrl = "~/image/PageIcon/jiangli.jpg";
                master.IntiBar();
            }
        }
        catch
        { }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Employees_EmpRecord));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DataCompressed = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SEmployees.EmpRecord";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

   
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string action = "";
        if (Request["action"] != null)
        {
            action = "&action=" + Request["action"].ToString();
        }

        string mode = "";
        if (Request["mode"] != null)
        {
            mode = "&mode=" + Request["mode"].ToString();
        }

        Response.Redirect("EmpRecordSelfList.aspx?eid=" + hidEid.Value + action + mode);
    }

    protected void wnHr_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdFirst" || e.CommandName == "cmdPrevious"
            || e.CommandName == "cmdNext" || e.CommandName == "cmdLast")
        {
            Master.ExecuteSelect(EmpRecord);
            DataBind();
        }
        else if (e.CommandName == "cmdAdd")
        {
            //Master.ExecuteAdd(Contract);
            DataBind();
          
        }
        else if (e.CommandName == "cmdDelete")
        {
            Master.ExecuteSelect(EmpRecord);
            DataBind();
        }
        else if (e.CommandName == "cmdApply" && EmpRecord.AllValidateSucess)
        {
            Master.ExecuteSelect(EmpRecord);
            DataBind();
            if (Request["action"] != null)
            {
                if (Request["action"].ToString() == "onlyadd")
                {
                    ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('添加成功');parent.location.reload()", true);
                }
            }
        }
    }

   

    protected void Master_Adding(object sender, Srvtools.WebDataSourceAddingEventArgs e)
    {
        try
        {
            Control_SelUser su = EmpRecord.FindControl("SelUser") as Control_SelUser;
            if (su.EmployeeId == "")
            {
                return;
            }
            else
            {
                e.AddingValues["EmployeeID"] = su.EmployeeId;

                hidEid.Value = su.EmployeeId;
                hidEname.Value = su.EmpName;
             
            }
        }
        catch
        {
            return;
        }


    }

    protected void EmpRecord_DataBound(object sender, EventArgs e)
    {
        if (Request["action"] != null)
        {
            if (Request["action"].ToString() == "view" || Request["action"].ToString() == "self")
            {
                wn.Visible = false;
            }
            
        }

        if (hidEid.Value != "")
        {
            Control_SelUser su = EmpRecord.FindControl("SelUser") as Control_SelUser;
            su.ReadOnly(hidEid.Value, hidEname.Value);

            if (Request["action"] != null)
            {
                if (Request["action"].ToString() == "onlyadd")
                {
                    spHistory.Visible = false;
                }
            }
        }
        else
        {
            Control_SelUser su = EmpRecord.FindControl("SelUser") as Control_SelUser;
            su.SelUserInti("", "");
        }
    }
}
